package com.a3dweijing.wetouch2.adapter;

import android.content.Context;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.view.ViewGroup;


import com.a3dweijing.wetouch2.fragment.ThreeDBusinessFragment;
import com.a3dweijing.wetouch2.fragment.ThreeDImageFragment;
import com.a3dweijing.wetouch2.fragment.ThreeDSpecialFragment;
import com.a3dweijing.wetouch2.fragment.ThreeDTVFragment;

import java.util.List;

/**
 * Created by Yxd on 2017/10/27.
 */

public class ThreeDViewpagerAdapter extends FragmentPagerAdapter {

    private Context context;
    private List<Fragment> fragments;
    private List<String> titles;
    public ThreeDViewpagerAdapter(FragmentManager fm, Context context, List<Fragment> fragments, List<String> titles) {
        super(fm);
        this.context = context;
        this.fragments = fragments;
        this.titles = titles;
    }

    @Override
    public Fragment getItem(int position) {
        switch (position)
        {
            case 0:
                if (fragments.get(position)!=null)
                {
                    return ThreeDTVFragment.newinstance();
                }
                break;
            case 1:
                if (fragments.get(position)!=null)
                {
                    return ThreeDSpecialFragment.newinstance();
                }
                break;
//            case 2:
//                if (fragments.get(position)!=null)
//                {
//                    return ThreeDOriginalFragment.newinstance();
//                }
//                break;
            case 2:
                if (fragments.get(position)!=null)
                {
                    return ThreeDImageFragment.newinstance();
                }
                break;
            case 3:
                if (fragments.get(position)!=null)
                {
                    return ThreeDBusinessFragment.newinstance();
                }
                break;
            default:
                if (fragments.get(1)!=null)
                {
                    return ThreeDSpecialFragment.newinstance();
                }
                break;
        }
        return fragments.get(position);
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
//        super.destroyItem(container, position, object);
    }

    @Override
    public int getCount() {
        return fragments.size();
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return titles.get(position);
    }
}
